﻿using Serilog;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace XjjXmm.Spider.biquge
{
    internal class HttpLogHandel<T> : DelegatingHandler
    {
        private static ILogger Logger = Log.ForContext<T>();

        protected override async Task<HttpResponseMessage> SendAsync(HttpRequestMessage request, CancellationToken cancellationToken)
        {
            DateTime begin = DateTime.Now;
            Logger.Information($"send requst:{request.Method}  {request.RequestUri}");
            var result = await base.SendAsync(request, cancellationToken);
                 
            var span = (DateTime.Now - begin).TotalMilliseconds;
            Logger.Information($"receive response after: {span}ms");

            return result;
        }
    }
}
